

import UIKit

class CZMainTableBalController: UITabBarController {

    override func viewDidLoad()
    {
        super.viewDidLoad()
         tabBar.tintColor = UIColor.orangeColor()
       //1.定义闭包
        let compseCallback = { () -> () in
               // TODO: Modal出控制器
            print("Model出控制器")
        }
        
        
        let mainTabBar = CZMainTabBar()
        //2.传递闭包
        mainTabBar.composeCallback=compseCallback
        // get,只读的属性,没有set方法, = 赋值调用的是set放法,只读属性没有了set就不能用=直接赋值
        // 使用KVC,KVC会先去找set方法如果没有set方法会找_tabBar成员变量,KVC使用运行时
        //        tabBar = mainTabBar
        setValue(mainTabBar, forKey: "tabBar")
        
      setChilderViewContorller()
    }
    /// 设置tabbar子控制器
    func setChilderViewContorller()
    {
        //首页
        let homeVc = ZHomeTableViewController()
        addChildViewController(homeVc,title: "首页",imageName: "tabbar_home")
       
        let messageVC = MessageViewController()
       
        addChildViewController(messageVC,title: "消息",imageName:"tabbar_message_center")
        
        let discoveyVC = CZDiscoveryViewController()
    addChildViewController(discoveyVC,title: "发现",imageName: "tabbar_discover")
        
        let profieVC = CZDiscoveryViewController()
      addChildViewController(profieVC,title: "我",imageName: "tabbar_profile")
    }
    /// 添加子控制器,设置标题和图片名称,并且包装导航控制器
    func addChildViewController (contorller:UIViewController, title:String, imageName:String)
    {
        
        //设置标题
        contorller.title = title
        //设置图片
        contorller.tabBarItem.image = UIImage (named: imageName)
//        //设置高亮图片
//        contorller.tabBarItem.image = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置文字选中颜色
        contorller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        //包装导航控制器
        addChildViewController(UINavigationController(rootViewController: contorller))
    }
    

}
